﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
    <title></title>
    <link href="../script/css/bootstrap.css" rel="stylesheet" />
    <script src="../script/js/jquery-1.12.3.js"></script>
    <script src="../script/js/bootstrap.js"></script>
    <script src="../script/js/cus-dirs.js"></script>
</head>
<body>
    <div class="container">

    </div>

    <script>
        $(function () {
            $.get('/api/index/MobileMenu', null, function (data) {
                var menu = data.data;
                var root = menu[0];
                var div = rec(root, menu);
                $('div.container').append(div);
            }).error(function () {
                window.location.href = "login.html";
            });
        });

        function rec(pobj, jdata) {
            var div = $('<div class="list-group" style="margin-top:1em;"></div>');
            for (var i = 0; i < jdata.length; i++) {
                var p = jdata[i];
                if (p.pid == pobj.id) {
                    var event = p.url == null ? 'onclick="tagglediv(this);"' : 'onclick="openurl(this, \'' + p.url.replace('~', '') + '?btns=' + p.btns + '\');"';
                    var icon = p.icon == null ? '<span class="glyphicon glyphicon-folder-close" aria-hidden="true"></span> '
                        : '<img src="' + p.icon.replace('~', '..') + '" style="width:1em;height:1em;"/> ';
                    var aa = $('<a href="#" class="list-group-item"><div ' + event + '>' + icon + p.name + '</div></a>');
                    var div1 = rec(p, jdata);
                    aa.append(div1);
                    div.append(aa);
                    $(div1).hide();
                }
            }
            return div.html() == "" ? "" : div;
        }

        function openurl(obj, url) {
            $('a').removeClass('active');
            $(obj).parent().addClass('active');
            window.location.href = url;
        }

        function tagglediv(obj) {
            $(obj).next().toggle();
            $('a').removeClass('active');
            $(obj).parent().addClass('active');
        }
    </script>
</body>
</html>
